package com.exp.practice.workbench.service.teacher.impl;

import com.exp.practice.workbench.dao.*;
import com.exp.practice.workbench.domain.Examination;
import com.exp.practice.workbench.domain.ExaminationSituation;
import com.exp.practice.workbench.domain.Question;
import com.exp.practice.workbench.service.teacher.TeacherAnalyseService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class TeacherAnalyseServiceImpl implements TeacherAnalyseService {

    @Resource
    private ExaminationStudentRelationDao examinationStudentRelationDao;

    @Resource
    private ExaminationDao examinationDao;

    @Resource
    private ExaminationSituationDao examinationSituationDao;

    @Resource
    private QuestionDao questionDao;

    @Resource
    private ExaminationQuestionRelationDao examinationQuestionRelationDao;

    //获得学生的试卷完成情况
    @Override
    public Map<String, Object> getFinishedSituation(String eid) {
        Map<String,Object> map=new HashMap<>();
        Integer unfinishedCount=examinationStudentRelationDao.getUnfinishedCount(eid);
        Integer finishedCount=examinationStudentRelationDao.getFinishedCount(eid);
        map.put("unfinishedCount",unfinishedCount);
        map.put("finishedCount",finishedCount);
        return map;
    }

    //获得某一试卷详情
    @Override
    public Examination getExamination(String eid) {
        Examination examination=examinationDao.getExaminationById(eid);
        return examination;
    }



    //获取该试卷所有已完成学生的答题情况中的姓名和成绩情况
    @Override
    public Map<String, Object> getExaminationSituation(String eid) {
        Map<String,Object> map=new HashMap<>();
        String[] names=examinationSituationDao.getNames(eid);
        String[] scores=examinationSituationDao.getScores(eid);
        map.put("names",names);
        map.put("scores",scores);
        return map;
    }

    //获取该试卷所有已完成学生的答题情况
    @Override
    public List<ExaminationSituation> getExaminationSituationList(String eid) {
        List<ExaminationSituation> list=new ArrayList<>();
        list=examinationSituationDao.getByEid(eid);
        return list;
    }

    @Override
    public ExaminationSituation getExaminationSituation(String eid, String stuId) {
        ExaminationSituation examinationSituation=examinationSituationDao.getByEidAndStuId(eid,stuId);
        return examinationSituation;
    }

    @Override
    public Map<String, Object> getConcreteExamination(String eid) {
        Map<String,Object> map=new HashMap<>();
        //获得试卷记录
        Examination examination=examinationDao.getExaminationById(eid);
        //获得题目记录
        String[]qids=examinationQuestionRelationDao.getIds(eid);

        List<Question> list=questionDao.getQuestions(0,qids.length,qids);
        //将结果加入map中
        map.put("examination",examination);
        map.put("questionList",list);
        return map;
    }
}
